/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Object;

import ClassFrame.CFont;
import ClassFrame.Resource;
import GamePlay.CanvasGame;
import javax.microedition.lcdui.Graphics;

/**
 *
 * @author HienPL
 */
public class Answer {
    public static final int w = 20;
    public static final int h = 20;
    
    private CanvasGame canvas;
    private int xCenter, y;
    private int count;

    public Answer(CanvasGame canvas, int xCenter, int y) {
        this.canvas = canvas;
        this.xCenter = xCenter;
        this.y = y;
        count = 0;
    }
    
    public void drawAnswer(Graphics g, String answer, String solution, CFont font){
        g.setColor(CanvasGame.BLACK);
        for(int i=0;i<solution.length();i++){
            if(i < answer.length()){
                if(answer.charAt(i) == ' '){

                } else {
                    canvas.getImage().drawImage(g, canvas, Resource.IMG_OCHU, xCenter - w/2*solution.length() + w*i, y);
                    if(answer.charAt(i) >= 'a' &&  answer.charAt(i) <= 'z'){ 
                        font.Render(g, (String)(String.valueOf((char)(answer.charAt(i) - 32))), xCenter - w/2*solution.length() + w*i + w/2, y + 3, CFont.ALIGN_CENTER);
                    } else { 
                        font.Render(g, (String)(String.valueOf(answer.charAt(i))), xCenter - w/2*solution.length() + w*i + w/2, y + 3, CFont.ALIGN_CENTER);
                    }
                }
            } else {
                canvas.getImage().drawImage(g, canvas, Resource.IMG_OCHU, xCenter - w/2*solution.length() + w*i, y);
                if(i == answer.length() && count%10 < 5){
                    font.Render(g, "|", xCenter - w/2*solution.length() + w*i + w/2-2, y + 3, CFont.ALIGN_CENTER);
                }
            }
        }
        count++;
    }
    
}
